<?php

namespace App\Middleware;

use App\Log;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;

class RequestMiddleware implements MiddlewareInterface
{

    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        if (config('app_env') !== 'product') {
            print_r(date('Y-m-d H:i:s') . "[=]request_uri:{$request->getUri()}; method:{$request->getMethod()}; body:" . substr($request->getBody()->getContents(), 0, 200) . " \n");
        }
        Log::get('sys')->info("request_uri:{$request->getUri()}; method:{$request->getMethod()}; body:" . substr($request->getBody()->getContents(), 0, 200));
        return $handler->handle($request);
    }
}